package com.laolang.shop.modules.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.laolang.shop.modules.product.entity.ProductAttrGroup;
import com.laolang.shop.modules.product.mapper.ProductAttrGroupMapper;
import com.laolang.shop.modules.product.pojo.attr.admin.vo.ProductAttrGroupPageVo;
import com.laolang.shop.modules.product.service.ProductAttrGroupService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

/**
 * @author khlbat
 * @version 1.0
 * @date 2020/11/4 15:49
 */
@AllArgsConstructor
@Service
public class ProductAttrGroupServiceImpl extends ServiceImpl<ProductAttrGroupMapper, ProductAttrGroup> implements ProductAttrGroupService {

    private final ProductAttrGroupMapper productAttrGroupMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean save(ProductAttrGroup entity) {
        entity.setVersion(1);
        entity.setCreateTime(LocalDateTime.now());
        return super.save(entity);
    }

    @Override
    public PageInfo<ProductAttrGroupPageVo> page(Integer page, Integer size, Long cateId) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(productAttrGroupMapper.page(cateId));
    }
}
